package com.cmall.common.foundation.util;

import java.util.*;

import com.cmall.common.foundation.constant.GlobalConstant;

/**
 * @Auther: lixin
 * @Date: 2018/10/23 09:52
 * @Description:
 */
public class CollectionsUtils {

    // 删除ArrayList中重复元素，保持顺序
    public static Map<String,Object> removeDuplicateWithItem(List list) {
        Map<String,Object> resultResulet = new HashMap<String,Object>();
        Set set = new HashSet();
        List newList = new ArrayList();
        int equalsItemCount = 0;
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            Object element = iter.next();
            if (set.add(element))
                newList.add(element);
            else
                equalsItemCount++;
        }
        list.clear();
        list.addAll(newList);
        resultResulet.put(GlobalConstant.EQUALS_ITEM_SIZE,equalsItemCount);
        resultResulet.put(GlobalConstant.EQUALS_ITEM_SIZE_RESULT,newList);
        return resultResulet;
    }
}
